package view;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;

import javax.imageio.ImageIO;
import javax.swing.JButton;
import javax.swing.JPanel;
import model.*;
import controller.*;

/*****************************************
 * leaderBoardPanel
 * 
 * Responsible for display leaderboard
 * 
 * 
 * @author Stephen Gregory, Jun Wang
 *
 */

public class leaderBoardPanel extends JPanel {

	private static final long serialVersionUID = -5035582131291476230L;
		BufferedImage bkgd;
		Font gameFont;
		JButton retButton = new JButton("Return to Main Menu");
		gameModelI model;
		//menuBar menu;

		public leaderBoardPanel(gameModelI m) {
			model = m;
			setLayout(null);
			setPreferredSize(new Dimension(1000, 600));	
			bkgd = null;	
			gameFont = new Font(Font.SANS_SERIF, Font.BOLD, 14);
			
			try {
				bkgd = ImageIO.read(new File("ldrbd.jpg"));
			} catch (IOException e) {}
			
	        
	        retButton.setBounds(780, 470, 160, 30); //x, y, width, height
	        add(retButton);
	  	
		}
	
	    public void paintComponent(Graphics g) {
	    	super.paintComponent(g);
			g.drawImage(bkgd, 0, 0, null);
	    	g.setColor(Color.white);
	    	g.setFont(gameFont);
	    	
	    	for (int i = 1; i <= model.getLeaderBoard().size(); i++) {
	    		g.drawString(i + ". " + model.getLeaderBoard().get(i-1).getName(), 400, 185+i*20);
	    		g.drawString(Integer.toString(model.getLeaderBoard().get(i-1).getScore()), 560, 185+i*20);
	    	}
	    	
	    }
	    
		@Override
		public boolean isFocusTraversable() {
		  return true;
		}
	    
		public void addReturnListener(ActionListener a) {
	        retButton.addActionListener(a);
	    }
}